﻿using zijian666.Abstractions;
using zijian666.Convertor;
using zijian666.Core;

namespace zijian666.Factory;

/// <summary>
/// 匿名类转换器 <seealso cref="AnonymousTypeConvertor{T}"/> 工厂
/// </summary>
public sealed class AnonymousTypeConvertorFactory : IConvertorFactory
{
    /// <inheritdoc/>
    public MatchedConvertor<T> Create<T>()
    {
        if (!typeof(T).IsArray && typeof(T).Name.StartsWith("<>f__AnonymousType"))
        {
            var convertor = new AnonymousTypeConvertor<T>();
            return new MatchedConvertor<T>(convertor, MacthedType.Equals);
        }
        return default;
    }
}
